package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.OrderReturnService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.utils.ExecuteResult;
import com.sun.showcase.client.domain.mall.OrderReturn;
import com.sun.showcase.client.query.mall.OrderReturnQuery;

@Controller
@RequestMapping(value="/mall/orderReturn") 
public class OrderReturnController{
	
	@Autowired
	private OrderReturnService orderReturnService;
	
	private Result result = new Result();
	/**
	 * 跳转到OrderReturn管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goOrderReturn")
	public String goOrderReturn() {
		return "mall/orderReturn";
	}
	/**
	 * 跳转到OrderReturn新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleOrderReturn")
	public String handleOrderReturn(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/orderReturn_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public OrderReturn showDesc(OrderReturnQuery orderReturnQuery) {
		return orderReturnService.get(orderReturnQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(OrderReturnQuery orderReturnQuery) {
		return orderReturnService.datagrid(orderReturnQuery);
	}
	

	/**
	 * 添加一个OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(OrderReturnQuery orderReturnQuery) {
		orderReturnService.add(orderReturnQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(OrderReturnQuery orderReturnQuery) {
		orderReturnService.update(orderReturnQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(OrderReturnQuery orderReturnQuery) {
		orderReturnService.delete(orderReturnQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(OrderReturnQuery orderReturnQuery) {
		orderReturnService.deletePt(orderReturnQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(OrderReturnQuery orderReturnQuery) {
		List<OrderReturnQuery> list = orderReturnService.listAll(orderReturnQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
	/**
	 * 全部数据OrderReturn
	 */
	@ResponseBody
	@RequestMapping(value="updateStatus")
	public Result updateStatus(String id ,String status) {
		ExecuteResult<String> e = orderReturnService.updateStatus(id , status);
		result.setSuccess(e.isSuccess());
		if(!e.isSuccess()) {
			result.setMsg(e.getErrorMessages().get(0));
		}else {
			result.setMsg("成功！");
		}
		return result;
	}
}
